﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR71Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR71Response))]
    public class RR71ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR71Response clazz;
        
        public RR71ResponseSerializer(IRR71Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("ttData");
            if (clazz.TtData!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute(">>>RR71Response>ttData>ttData", "http://producers.rr.xtee.riik.ee/producer/rr", clazz.TtData.Count);
                for (int x = 0; ((clazz.TtData != null) 
                            && (x < clazz.TtData.Count)); x = (x + 1)) {
                    if (clazz.TtData[x]!=null) {
                        Writer.WriteStartElement("ttData");
                        global::Xtee.Core.SerializationMetadata metaTtData = this.GetMetaData(clazz.TtData[x]);
                        Writer.WriteTypeAttribute(metaTtData.TypeQualifiedName.Namespace, metaTtData.TypeQualifiedName.Name);
                        metaTtData.NewSerializer(clazz.TtData[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TtData");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ttData") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR71Response>ttData");
                }
                clazz.TtData = new System.Collections.Generic.List<RR71Response.ITtDataType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("ttData");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "ttData")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RR71Response>ttData>ttData");
                        }
                        global::Xtee.Core.SerializationMetadata metaTtData = this.GetMetaData<RR71Response.ITtDataType>(Reader, ">>>RR71Response>ttData>ttData", "http://producers.rr.xtee.riik.ee/producer/rr");
                        RR71Response.ITtDataType item = metaTtData.NewEntity<RR71Response.ITtDataType>();
                        clazz.TtData.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("ttData");
                            metaTtData.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR71Response>ttData", Reader.LocalName);
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RR71Response>ttData>ttData", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR71Response.TtDataType))]
        public class TtDataTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RR71Response.ITtDataType clazz;
            
            public TtDataTypeSerializer(RR71Response.ITtDataType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("ttData.id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.TtDataid))).ToString());
                Writer.WriteEndElement();
                Writer.WriteStartElement("ttData.cData");
                if (clazz.TtDatacData!=null) {
                    Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.TtDatacData))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : TtDatacData");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="ttData.id") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR71Response>ttData>ttData>ttData.id");
                    }
                    clazz.TtDataid = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ttData.id")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR71Response>ttData>ttData>ttData.id", Reader.LocalName);
                }
                if (Reader.LocalName=="ttData.cData") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RR71Response>ttData>ttData>ttData.cData");
                    }
                    clazz.TtDatacData = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ttData.cData")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RR71Response>ttData>ttData>ttData.cData", Reader.LocalName);
                }
            }
        }
    }
}
